#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_fop_prop2.info <<'%EOF%'
   cc_fop_prop2
   ------------
   Molecule:         N2 in D2h
   Wave Function:    CCS, CC2 / cc-pVDZ
   Test Purpose:     First-order one-electron properties
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_fop_prop2.mol <<'%EOF%'
BASIS
cc-pVDZ
first order property calculation on N2
small test-basis
    1    3  X  Y  Z   1.00D-15
        7.0   1    3    1    1    1
N     0.0000000000000000  0.0000000000000000 1.03715750000000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_fop_prop2.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.THETA
.EFGCAR
.SECMOM
.DARWIN
.MASSVELO
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-10
.DOUBLY OCCUPIED
 3 1 1 0 2 0 0 0
*CC INP
.CCS
.CC2
.PRINT
 6
.THRENR
1.0D-10
.THRLEQ
1.0D-07
*CCFOP
.ALLONE
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_fop_prop2.check
cat >>cc_fop_prop2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy: * -108\.95413072326" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -109\.264721936" $log | wc -l`
CRIT3=`$GREP "Total CC2   energy: * -109\.269782947" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"


# CCS first order properties :
CRIT1=`$GREP  "1 * ( |0)\.5636754. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT2=`$GREP  "2 * ( |0)\.0000000. * ( |0)\.5636754. * ( |0)\.0000000" $log | wc -l`
CRIT3=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * -1\.1273509" $log | wc -l`
CRIT4=`$GREP  "1 * 7\.5394261. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT5=`$GREP  "2 * ( |0)\.0000000. * 7\.5394261. * ( |0)\.0000000" $log | wc -l`
CRIT6=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. *  23\.7265166" $log | wc -l`
CRIT7=`$GREP  "Alfa\*\*2 Invariant: * 167\.31740" $log | wc -l`
CRIT8=`$GREP  "Beta\*\*2 Invariant: * 262\.02189" $log | wc -l`
CRIT9=`$GREP "Isotropic Property:  * 12\.93512. a\.u\." $log | wc -l`
CRIT10=`$GREP "Property anisotropy invariant: * 16\.18709. a\.u\." $log | wc -l`
CRIT11=`$GREP "1 * ( |0)\.5742711. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT12=`$GREP "2 * ( |0)\.0000000. * ( |0)\.5742711. * ( |0)\.0000000" $log | wc -l`
CRIT13=`$GREP "3 * ( |0)\.0000000. * ( |0)\.0000000. * -1\.1485423" $log | wc -l`
CRIT14=`$GREP "N   _1 14    Vx =       ( |0)\.57427.     2\.75804.     ( |0)\.98527" $log | wc -l`
CRIT15=`$GREP "N   _1 14    Vy =       ( |0)\.57427.     2\.75804.     ( |0)\.98527" $log | wc -l`
CRIT16=`$GREP "N   _1 14    Vz =      -1\.14854.    -5\.51608.    -1\.97055" $log | wc -l`
CRIT17=`$GREP "1-elec\. Darwin term: *( |0)\.23063641" $log | wc -l`
CRIT18=`$GREP "Mass-Velocity term: *( -|-0)\.28863568" $log | wc -l`
CRIT19=`$GREP "Mass-Velocity \+ 1-elec\. Darwin terms: *( -|-0)\.05799926" $log | wc -l`
CRIT20=`$GREP "Ecorr = * -108\.9541307232(5|6)" $log | wc -l`

TEST[2]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10 \+ \
              $CRIT11 \+ $CRIT12 \+ $CRIT13 \+ $CRIT14 \+ $CRIT15 \+ \
              $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ $CRIT19 \+ $CRIT20`
CTRL[2]=23
ERROR[2]="CCS FIRST ORDER PROPERTIES NOT CORRECT"


# CC2 first order properties :
CRIT1=`$GREP  "1 * ( |0)\.6959127. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT2=`$GREP  "2 * ( |0)\.0000000. * ( |0)\.6959127. * ( |0)\.0000000" $log | wc -l`
CRIT3=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * -1\.3918254" $log | wc -l`
CRIT4=`$GREP  "1 * 7\.3950988. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT5=`$GREP  "2 * ( |0)\.0000000. * 7\.3950988. * ( |0)\.0000000" $log | wc -l`
CRIT6=`$GREP  "3 * ( |0)\.0000000. * ( |0)\.0000000. * 23\.8466638" $log | wc -l`
CRIT7=`$GREP  "Alfa\*\*2 Invariant: * 165\.86745" $log | wc -l`
CRIT8=`$GREP  "Beta\*\*2 Invariant: * 270\.6539(8|9)" $log | wc -l`
CRIT9=`$GREP "Isotropic Property:  * 12\.87895. a\.u\." $log | wc -l`
CRIT10=`$GREP "Property anisotropy invariant: * 16\.45156. a\.u\." $log | wc -l`
CRIT11=`$GREP "1 * ( |0)\.4518694. * ( |0)\.0000000. * ( |0)\.0000000" $log | wc -l`
CRIT12=`$GREP "2 * ( |0)\.0000000. * ( |0)\.4518694. * ( |0)\.0000000" $log | wc -l`
CRIT13=`$GREP "3 * ( |0)\.0000000. * ( |0)\.0000000. * ( -|-0)\.9037388" $log | wc -l`
CRIT14=`$GREP "N   _1 14    Vx =       ( |0)\.45186.     2\.17018.     ( |0)\.77527" $log | wc -l`
CRIT15=`$GREP "N   _1 14    Vy =       ( |0)\.45186.     2\.17018.     ( |0)\.77527" $log | wc -l`
CRIT16=`$GREP "N   _1 14    Vz =      ( -|-0)\.90373.    -4\.34036.    -1\.55054" $log | wc -l`
CRIT17=`$GREP "   1-elec\. Darwin term: *( |0)\.23056651" $log | wc -l`
CRIT18=`$GREP "   Mass-Velocity term: *( -|-0)\.28868401" $log | wc -l`
CRIT19=`$GREP "   Mass-Velocity \+ 1-elec\. Darwin terms: *( -|-0)\.05811749" $log | wc -l`
CRIT20=`$GREP "Ecorr = * -109\.26978294756" $log | wc -l`

TEST[3]=`expr $CRIT1  \+ $CRIT2  \+ $CRIT3  \+ $CRIT4  \+ $CRIT5  \+ \
              $CRIT6  \+ $CRIT7  \+ $CRIT8  \+ $CRIT9  \+ $CRIT10 \+ \
              $CRIT11 \+ $CRIT12 \+ $CRIT13 \+ $CRIT14 \+ $CRIT15 \+ \
              $CRIT16 \+ $CRIT17 \+ $CRIT18 \+ $CRIT19 \+ $CRIT20`
CTRL[3]=23
ERROR[3]="CC2 FIRST ORDER PROPERTIES NOT CORRECT"


PASSED=1
for i in 1 2 3
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
